
import {legacy_createStore as createStore,combineReducers} from "redux"

function msgReducer(state = {msg:"我是初始值"},action){
    //具体修改数据的行为
    switch(action.type){
        case 'changeMsg':
            state.msg = action.payload
            //最后要return state 并且展开解除引用
            return {...state}
        case "resetMsg":
            state.msg = "我是初始值"    
            return {...state}
        default:
            return {...state}  
    }
}


function numReducer(state = {num:0},action){
    //具体修改数据的行为
    switch(action.type){
        case 'addNum':
            state.num += 1
            //最后要return state 并且展开解除引用
            return {...state}
        case "resetNum":
            state.msg = 999   
            return {...state}
        default:
            return {...state}  
    }
}


//多模块
let combine = combineReducers({
    msgReducer,
    numReducer
})



let store = createStore(combine)


export default store